package com.sqin.taskflow.config;

import com.sqin.taskflow.listener.GlobalTaskListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * @program: edms
 * @description: 流程全局监听
 * @author: HO
 * @create: 2020-05-15 15:02
 */
@Configuration
public class FlowableGlobListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private SpringProcessEngineConfiguration configuration;
    @Autowired
    private GlobalTaskListener globalTaskListener;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.TASK_CREATED);
        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.TASK_COMPLETED);
        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.PROCESS_COMPLETED);
        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.PROCESS_CREATED);
        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.PROCESS_STARTED);
        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.JOB_EXECUTION_SUCCESS);
        dispatcher.addEventListener(globalTaskListener, FlowableEngineEventType.JOB_EXECUTION_FAILURE);

    }
}